package com.wh.controller.initial;

import com.wh.pojo.Storehouse;
import com.wh.service.initial.StorehouseService;
import com.wh.vo.PageResult;
import com.wh.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/storehouse/")
public class StorehouseController {

    @Autowired
    private StorehouseService storehouseService;

    @GetMapping("list")
    public SysResult getStorehouseList(PageResult pageResult){
        pageResult = storehouseService.getStorehouseList(pageResult);
        return SysResult.success(pageResult);
    }

    @PostMapping("addStorehouse")
    public SysResult addStorehouse(@RequestBody Storehouse storehouse){
        storehouseService.addStorehouse(storehouse);
        return SysResult.success();
    }

    @PutMapping("updataStorehouse")
    public SysResult updataStorehouse(@RequestBody Storehouse storehouse){
        storehouseService.updataStorehouse(storehouse);
        return SysResult.success();
    }

    @DeleteMapping("delete/{name}")
    public SysResult deleteStorehouse(@PathVariable String name) throws Exception {
        storehouseService.deleteStorehouse(name);
        return SysResult.success();
    }
}
